package cn.xiaoyuan.service.impl;

import cn.xiaoyuan.dao.UserMapper;
import cn.xiaoyuan.entity.Product;
import cn.xiaoyuan.entity.Sell;
import cn.xiaoyuan.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;
    @Override
    public List<Sell> getSellByUser(int uid) {
       return userMapper.getSellByUser(uid);
    }

    @Override
    public boolean delete_sellId(int id) {
        return userMapper.delete_sellId(id) > 0;
    }

    @Override
    @Transactional
    public void insertProduct(String ptitle, String pdesc,int uid) {
        Product product=new Product().setPtitle(ptitle).setPdesc(pdesc).setId(0);
        if(userMapper.insertProduct(product)<0){
            throw new RuntimeException("添加基本信息失败");
        }
        System.out.println(product.getId());
        if(userMapper.insertSeller(product.getId(),uid)<0){
            throw new RuntimeException("添加关系失败");
        }
    }

    @Override
    public int up_sell(int id) {
        // userMapper.update();
        return 0;
    }

    @Override
    public Product getProductById(int id) {
      return userMapper.getProductById(id);
    }
}
